<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page
	import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>千禧宝贝连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>

<script>
function updateOrdersTest(){
	var params = $("#SalesOrderForm").serialize();  
	$.post("chainSalesJSONAction!updateSalesOrder",params, backProcessUpdateOrder,"json");
}

function backProcessUpdateOrder(data){
	//$.messager.alert('更新信息', data.message, 'info');
	alert(data.message);
}
/**
 * 修改单据经手人
 */
function updateOrders(){
    $.messager.prompt('修改单据确认', '修改密码', function(r){
        if (r){
        	if (r == 'vj7683c6'){
        	  var params = $("#SalesOrderForm").serialize();  
        	  $.post("chainSalesJSONAction!updateSalesOrder?formBean.token=123456789",params, backProcessUpdateOrder,"json");
        	} else 
        		$.messager.alert('错误', '密码错误', 'error');
        } 
        	
    });

}

function updateOrdersStatus(){
	var params = $("#SalesOrderForm").serialize();  
	$.post("chainSalesJSONAction!updateSalesOrderStatus",params, backProcessUpdateOrderStatus,"json");
}

/**
 * 隐藏单据
 */
function hideOrders(){
    $.messager.prompt('隐藏单据确认', '修改密码', function(r){
        if (r){
        	if (r == 'vj7683c6'){
        	  var params = $("#SalesOrderForm").serialize();  
        	  $.post("chainSalesJSONAction!updateSalesOrderStatus?formBean.token=123456789",params, backProcessUpdateOrderStatus,"json");
        	} else 
        		$.messager.alert('错误', '密码错误', 'error');
        } 
        	
    });
}

function backProcessUpdateOrderStatus(data){
	alert(data.message);
}

/**
 * after change the chain store, we need change the user list and customer groups as well
 */
function changeChainStore(chainId){
	var params = "formBean.chainSalesOrder.chainStore.chain_id=" + chainId;
	$.post("chainSalesJSONAction!changeChainStore",params, backProcessChangeChainStore,"json");
}
function backProcessChangeChainStore(data){
	var chainUsers =  data.chainUsers;
	$("#chainSaler").empty();
	$("#toChainSaler").empty();
	if (chainUsers.length != 0 ){
		for (var i = 0; i < chainUsers.length; i++){
			$("#chainSaler").append("<option value='"+chainUsers[i].user_id+"'>"+chainUsers[i].name+"</option>");
			$("#toChainSaler").append("<option value='"+chainUsers[i].user_id+"'>"+chainUsers[i].name+"</option>");
		}	    
	}
}
</script>
</head>
<body>
	<s:form id="SalesOrderForm"
		action="/actionChain/salesAction!searchOrders" theme="simple"
		method="POST">
		<input type="hidden" id="indicator" name="formBean.indicator"
			value="0" />
		<input type="hidden" id="accessLevel" name="formBean.accessLevel"
			value="4" />
		<table width="98%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
						<tr>
							<td height="50" colspan="7">
								<table width="100%" border="0">
									<tr class="InnerTableContent">
										<td height="10" colspan="7"><s:actionerror
												cssStyle="color:red" />
											<s:actionmessage cssStyle="color:blue" /></td>
									</tr>
									<tr class="InnerTableContent">
										<td width="45" height="30">&nbsp;</td>
										<td width="76"><strong>单据日期</strong></td>
										<td width="284"><s:textfield id="startDate"
												name="formBean.search_Start_Time" cssClass="easyui-datebox"
												data-options="width:100,editable:false" /> &nbsp; 至&nbsp; <s:textfield
												id="endDate" name="formBean.search_End_Time"
												cssClass="easyui-datebox"
												data-options="width:100,editable:false" /></td>
										<td width="71"><strong>容错率</strong></td>
										<td width="140"><input type="text" name="formBean.chainOrderPay" value="10"/></td>
										<td width="77"></td>
										<td></td>
									</tr>
									<tr class="InnerTableContent">
										<td height="30">&nbsp;</td>
										<td><strong>连锁店</strong></td>
										<td><%@ include file="../include/SearchChainStore.jsp"%></td>
										<td><strong>原经手人</strong></td>
										<td><s:select id="chainSaler"
												name="formBean.chainSalesOrder.saler.user_id"
												list="uiBean.chainSalers" listKey="user_id" listValue="name"/></td>
										<td></td>
										<td></td>
									</tr>
									<tr class="InnerTableContent">
										<td height="30">&nbsp;</td>
										<td>修正金额</td>
										<td><input type="text" name="formBean.chainSalesOrder.totalAmount" value="0"/></td>
										<td><strong>新经手人</strong></td>
										<td><s:select id="toChainSaler"
												name="formBean.chainSalesOrder.creator.user_id"
												list="uiBean.chainSalers" listKey="user_id" listValue="name" /></td>
										<td></td>
										<td></td>
									</tr>
									<tr class="InnerTableContent">
										<td height="25">&nbsp;</td>
										<td>&nbsp;</td>
										<td colspan="2"><s:if
												test="#session.LOGIN_CHAIN_USER.containFunction('chainSalesJSONAction!searchSalesOrder')">
												<input type="button" value="模拟修改单据" onclick="updateOrdersTest();" />
												<input type="button" value="修改单据" onclick="updateOrders();" />
											</s:if></td>
										<td>&nbsp;</td>
										<td>&nbsp;</td>
										<td>&nbsp;</td>
									</tr>
									<tr class="InnerTableContent">
										<td height="25">&nbsp;</td>
										<td>&nbsp;</td>
										<td colspan="2"><s:if
												test="#session.LOGIN_CHAIN_USER.containFunction('chainSalesJSONAction!searchSalesOrder')">
												<input type="button" value="模拟隐藏单据" onclick="updateOrdersStatus();" />
												<input type="button" value="隐藏单据" onclick="hideOrders();" />
											</s:if></td>
										<td>&nbsp;</td>
										<td>&nbsp;</td>
										<td>&nbsp;</td>
									</tr>									
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</s:form>
	<script>
$(document).ready(function(){
	parent.$.messager.progress('close'); 
});
</script>
</body>
</html>